// 实现reduce map filter
Array.prototype.myReduce = function (callback, initValue) {
    let acc = initValue ? initValue : this[0];
    for (let i = 0; i < this.length; i++) {
        let _this = this
        acc = callback(acc, this[i + 1], i, _this)
    }
    return acc
}


// flat
Array.prototype.myFlat = function (num = 1) {
    if (Array.isArray(this)) {
        let arr = [];
        if (!Number(num) || Number(num) < 0) {
            return this
        }
        this.forEach((item) => {
            if (Array.isArray(this)) {
                let count = num;
                arr = arr.concat(item.myFlat(count--))
            } else {
                arr.push(item)
            }
        })
        return arr
    } else {
        throw "this .flat is not function"
    }

}

// map 
Array.prototype.map = function (callback, thisArg) {
    let arr = [];
    for (let i = 0; i < this.length; i++) {
        arr.push(callback.call(thisArg, this[i], i, this))
    }
    return arr
}

// isArray
Array.prototype.nyIsArray = function(obj){
    return Object.prototype.toString.call(Object(obj)) === "[Object Array]"
}